//---------------------------------------------------------------------
// Author: jachymko
//
// Description: StaticExpression tab expansion handler tests
//
// Creation Date: Dec 31, 2006
//---------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using System.Text;
using NUnit.Framework;
using Pscx.Commands;

namespace PscxUnitTests.TabExpansion
{
    public class TabExpansionTestBase : PscxCmdletTest
    {
        protected string[] GetExpansions(string line, string word)
        {
            Command getTabExpansion = new Command("Get-TabExpansion");
            getTabExpansion.Parameters.Add("Line", line);
            getTabExpansion.Parameters.Add("LastWord", word);

            Collection<PSObject> objects = Invoke(getTabExpansion);
            List<string> expansions = new List<string>();

            foreach (PSObject obj in objects)
            {
                string str = obj.BaseObject as string;
                if (str != null)
                {
                    expansions.Add(str);
                }
            }

            return expansions.ToArray();
        }

        protected void AssertExpansions(string word, string[] expected)
        {
            AssertExpansions(word, word, expected);
        }
        protected void AssertExpansions(string line, string word, string[] expected)
        {
            string[] actual = GetExpansions(line, word);
            
            Assert.IsNotNull(actual);
            Assert.IsNotEmpty(actual);
            Assert.AreEqual(expected.Length, actual.Length);

            foreach (string exp in expected)
            {
                Assert.Contains(exp, actual, "The expected string '{0}' was not returned.", exp);
            }
        }

        [SetUp]
        public void StartTabExpansion()
        {
            Invoke("Start-TabExpansion");
        }
    }
}
